package com.ct.ecommerce.uc.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ct.ecommerce.uc.dao.entity.UserEntity;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author changtong
 * @since 2021/5/23
 */
public interface UserMapper extends BaseMapper<UserEntity> {

    @Select("select distinct p.name from ec_permission p "
        + "left join ec_role2permission r2p on p.id = r2p.permission_id "
        + "left join ec_role r on (r2p.role_id = r.id and r.record_status = 1) "
        + "left join ec_user2role u2r on r.id = u2r.role_id "
        + "left join ec_user u on (u2r.user_id = u.id and u.record_status = 1) "
        + "where p.record_status = 1 and u.id = #{userId}")
    List<String> findUserPermissionByUserId(@Param("userId") Long userId);

}
